package com.zaoyidian.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zaoyidian.common.ResponseCode;
import com.zaoyidian.common.ServerResponse;
import com.zaoyidian.dao.ProductMapper;
import com.zaoyidian.pojo.Product;
import com.zaoyidian.service.IProductService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Gahins on 2017/8/14.
 */
@Service("iProductService")
public class ProductServiceImpl implements IProductService {

    @Autowired
    private ProductMapper productMapper;

    public ServerResponse<PageInfo> getProductByShopId(Integer shopId, int pageNum, int pageSize, String orderBy){
        if(shopId==null){
            return ServerResponse.createByErrorCodeMessage(ResponseCode.ILLEGAL_ARGUMENT.getCode(), ResponseCode.ILLEGAL_ARGUMENT.getDesc());
        }
        PageHelper.startPage(pageNum,pageSize);
        // TODO: 2017/8/14  排序处理
        List<Product> productList=productMapper.selectByShopId(shopId);
        PageInfo pageInfo = new PageInfo(productList);
        return ServerResponse.createBySuccess(pageInfo);
    }
}
